package two.chapter_5.c5_1;

import edu.princeton.cs.algs4.In;
import edu.princeton.cs.algs4.StdOut;

public class Count {
    public static void main(String[]args){

        Alphabet alphabet=new Alphabet("0123456789");
        int R=alphabet.radix();
        int count[]=new int[R];

        String file="/Users/wind/downloads/高焕堂EIT/Algorithms-master/data/pi.txt";
        In in=new In(file);
        String s=in.readAll().replace("\n","");
        int N=s.length();
        int[] a=alphabet.toIndices(s);
        for (int i=0;i<N;i++){
            count[a[i]]++;
        }
       /* for (int i = 0; i < N; i++) {
            if (alphabet.contains(s.charAt(i))){
                count[alphabet.toIndex(s.charAt(i))]++;
            }
        }*/
        for (int c = 0; c <R; c++) {
            StdOut.println(alphabet.toChar(c)+" "+count[c]);
        }
    }
}
